package com.danger.Activity.Setting;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.Toolbar;
import android.widget.TextView;
import com.danger.Activity.BackHandledFragment;
import com.danger.Activity.BackHandledInterface;
import com.danger.Activity.R;
import com.danger.MyApplication;

public class SettingActivity extends AppCompatActivity implements BackHandledInterface {

    private BackHandledFragment selectedFragment;
    private Toolbar setting_toolbar;
    private TextView toolbar_title;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        MyApplication.getInstance().addActivity(this);
        setContentView(R.layout.activity_setting);

        initView();

        if(savedInstanceState == null) {
            getFragmentManager().beginTransaction().add(R.id.setting_container, new SettingFragment()).commit();
        }
    }

    private void initView() {
        setting_toolbar = (Toolbar) findViewById(R.id.setting_toolbar);
        toolbar_title = (TextView) findViewById(R.id.toolbar_title);
    }

    @Override
    public void onBackPressed() {
        if (selectedFragment == null || !selectedFragment.onBackPressed()) {
            if (getFragmentManager().getBackStackEntryCount() == 0) {
                super.onBackPressed();
            } else {
                getFragmentManager().popBackStack();
            }
        }
    }

    @Override
    public void setSelectedFragment(BackHandledFragment selectedFragment) {
        this.selectedFragment = selectedFragment;
    }

    public TextView getTextViewTitle() {
        return toolbar_title;
    }

    public Toolbar getToolbar() {
        return setting_toolbar;
    }
}